<template>
  <div class="login-wrapper">
    <div class="login-info">
      <div class="login-item">
        <h1>局域网IM系统</h1>
      </div>
      <div class="login-item">
        <label>账号</label>
        <input v-model="account" type="text" placeholder="请输入手机号" />
      </div>
      <div class="login-item">
        <label>密码</label>
        <input v-model="pwd" type="password" placeholder="请输入密码" />
      </div>
      <div class="login-item small">
        <span @click="register">注册？</span>
      </div>
      <div class="login-item">
        <div class="login-btn" @click="login">LOGIN</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      account: '1523386688',
      pwd: '1q2w3e4rQAZ@'
    }
  },
  methods: {
    login() {
      if (this.account === '' || this.pwd === '') {
        alert('账号或密码不能为空');
        return;
      }

      this.$axios.post('/users/login', { account: this.account, pwd: this.pwd }).then(res => {
        const data = res.data;
        if (data.code === 200) {
          alert(data.msg);
          this.$router.replace('/index')
          this.$storage.setItem('userinfo', JSON.stringify(data.data));
          this.$storage.setItem('account', data.data.id);
          sessionStorage.setItem('isLogin', true);
        } else {
          alert(data.msg);
        }
      }).catch(err => {
        console.log(err)
      })
    },
    register() {
      this.$router.push('/register')
    }
  }
}
</script>

<style scoped>
.login-wrapper {
  width: 100%;
  height: 100%;
  background-color: rgb(17, 232, 178);
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-info {
  display: flex;
  flex-direction: column;
  width: 50%;
  height: 50%;
  background-color: rgb(13, 13, 13);
  border-radius: 10px;
}

.login-info .login-item {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-info .login-item.small {
  height: 20px !important;
  flex: 0;
}

.login-info .login-item.small span {
  color: rgb(255, 255, 255);
}

.login-info .login-item input {
  width: 200px;
  height: 30px;
  border-radius: 5px;
  border: none;
  outline: none;
  padding-left: 10px;
}
.login-info .login-item label {
  height: 30px;
  line-height: 30px;
  color: rgb(255, 255, 255);
  font-size: 16px;
  text-align: right;
  margin-right: 10px;
}

.login-info .login-item h1 {
  color: rgb(255, 255, 255);
  font-size: 30px;
  text-align: center;
}

.login-btn {
  width: 100px;
  height: 40px;
  background-color: rgb(255, 255, 255);
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
</style>